#ifndef _BL_BYTECONVERTER_H__
#define _BL_BYTECONVERTER_H__

#include "blplateform/Define.h"
#include <iostream>

namespace ByteConverter
{
    template<size_t T>
        inline void convert(char *val)
    {
        std::swap(*val, *(val + T - 1));
        convert<T - 2>(val + 1);
    }

    template<> inline void convert<0>(char *) {}
    template<> inline void convert<1>(char *) {}            // ignore central byte

    template<typename T> inline void apply(T *val)
    {
        convert<sizeof(T)>((char *)(val));
    }
}

#if BL_ENDIAN == BL_BIGENDIAN
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
#else
template<typename T> inline void EndianConvert(T&) { }
#endif

template<typename T> inline void EndianConvert(T*) { }
inline void EndianConvert(uint8&) { }
inline void EndianConvert( int8&) { }

#endif
